package com.lida.wechat.controller;

import com.lida.wechat.service.PayService;
import com.lida.wechat.utils.GetWeixinUrlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("api/pay")
public class PayController {

    @Autowired
    private PayService payService;

    @RequestMapping(value = "image", method = RequestMethod.GET)
    public void payWexin(@RequestParam String ip, HttpServletResponse response) throws Exception {
        String url = GetWeixinUrlUtil.weixin_pay(ip);
        GetWeixinUrlUtil.encodeQrcode(url, response);
    }

    @RequestMapping(value = "weixinNotify", method = RequestMethod.POST)
    public void weixinNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        payService.weixinNotify(request, response);
    }
}
